﻿var JBDPage = JBDPage || {};

JBDPage.editButtons = {

	init : function() {

		var myButton = document.getElementsByClassName("EditB");
		var formContent = document.getElementById("formContent");
		var statusString = document.getElementById("statusString");

		if (myButton.length != 0) {

			var length = myButton.length;

			for (var i = 0; i < length; i++) {

				var myA = this.createLink(i);
				myButton[i].appendChild(this.createLink(i));
			}
		}

		if (statusString.innerHTML != "") {
			formContent.setAttribute("class", "");
		}

		if (formContent != null) {

			if (formContent.getAttribute("class") == "hide") {
				formContent.setAttribute("class", "hide");
			}

			if (formContent.getAttribute("class") == "") {
				formContent.setAttribute("class", "");
			}

			var accountHeading = document.getElementById("accountHeading");

			var a;
			a = document.createElement("a");
			a.href = "#";
			a.innerHTML = "Psst - Prova med Admin och 123";

			var openImg;
			openImg = document.createElement("img");
			openImg.src = "_img/open_close.png";

			a.appendChild(openImg);
			accountHeading.appendChild(a);

			a.onclick = function() {
				if (document.getElementById("formContent").getAttribute("class") == "hide") {
					document.getElementById("formContent").setAttribute("class", "");
				} else {
					document.getElementById("formContent").setAttribute("class", "hide");
				}
				return false;
			};
		}

	}
};

function createLink(i) {

	var a = document.createElement("a");
	a.innerHTML = "Redigera";
	a.setAttribute("class", "JBlink");
	a.href = "#";

	var str = "hidden";
	var string = i.toString();
	var name = str.concat(string);

	a.onclick = function() {

		if (document.getElementById(name).getAttribute("class") == "hide") {

			document.getElementById(name).setAttribute("class", "");
			a.innerHTML = "Stäng";

		} else {
			document.getElementById(name).setAttribute("class", "hide");
			a.innerHTML = "Redigera";
		}

	};
	return a;
};

window.onload = JBDPage.editButtons.init;
